import React, { PureComponent } from "react";
import { connect } from "react-redux";
import Home from "components/Home";
import ListTab from "components/ProjectList/Home/ListTab";
import Assignment from "../Assignment";
import Direct from "../Direct";
import AxHeader from "components/AxHeader";
import { hashHistory, router } from "React-router";
import s from "./index.scss";
export default class extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      tabIndex: 1,
      loading: true,
      directOrAssign: 1 //1为direct 2为assign
    };
  }
  
  componentDidMount() {
    if (this.props.location.query.flag == 1) {
      this.setState({ directOrAssign: 1 });
      // console.log(this.state.directOrAssign);
    } else if (this.props.location.query.flag == 2) {
      this.setState({ directOrAssign: 2 });
      // console.log(this.state.directOrAssign);
    }
  }
  componentWillReceiveProps(nextProps) {
    // console.log(nextProps.location.query);
    if (
      nextProps.location.query.flag == 1 ||
      nextProps.location.query.flag == undefined
    ) {
      this.setState({ directOrAssign: 1 });
      // console.log(this.state.directOrAssign);
    } else if (nextProps.location.query.flag == 2) {
      this.setState({ directOrAssign: 2 });
      // console.log(this.state.directOrAssign);
    }
  }
  
  //销毁时解绑事件
  componentWillUnmount() {
    //重写组件的setState方法，直接返回空
    this.setState = (state, callback) => {
      return;
    };
  }

  

  onSwitchTab = pathname => {
    hashHistory.push({ pathname: pathname });
  };

  render() {
    const { children } = this.props;
    let { directOrAssign } = this.state;
    // console.log(directOrAssign);
    return (
      <div>
        <div className={`${s.fixedHead}`}>
          <AxHeader/>
          <ListTab onSwitchTab={this.onSwitchTab} />
        </div>
        <div className={`${s.block}`} ></div>
        {directOrAssign == 1 ? <Direct directOrAssign={directOrAssign}/> : <Assignment directOrAssign={directOrAssign}/>}
        {children}
      </div>
    );
  }
}
